import { withUser, parseBody, json } from "@/lib/api"; import { getPrompt, updatePrompt, deletePrompt, toPublicPrompt } from "@/lib/prompts/service"; import { promptBodySchema } from "@/lib/prompts/schemas"; export const dynamic = "force-dynamic"; type P = { id: string }; /** GET /api/prompts/:id → { prompt } */ export const GET = withUser
(async ({ user }, { id }) => json({ prompt: toPublicPrompt(await getPrompt(user.id, id)) })); /** PATCH /api/prompts/:id (any subset of the create body) → { prompt } */ export const PATCH = withUser
(async ({ req, user }, { id }) => { const body = await parseBody(req, promptBodySchema.partial()); return json({ prompt: await updatePrompt(user.id, id, body) }); }); export const DELETE = withUser
(async ({ user }, { id }) => { await deletePrompt(user.id, id); return json({ ok: true }); });